import 'package:boss/models/package_group.dart';
import 'package:boss/provider/package_group_provider.dart';
import 'package:boss/ui/page/packageGroup/page/packageGroupDetail/package_group_detail_page.dart';
import 'package:boss/ui/page/packageGroup/widget/package_group_item.dart';
import 'package:boss/ui/widget/loader/empty_widget.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PackageGroupList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Consumer<PackageGroupProvider>(
        builder: (context, packageGroupProvider, _) {
          if (packageGroupProvider.packageGroups.length == 0) return EmptyWidget();

          return ListView.builder(
            padding: EdgeInsets.symmetric(
              horizontal: 30.w,
            ),
            itemBuilder: (context, index) {
              var current = packageGroupProvider.packageGroups[index];

              return PackageGroupItem(
                data: current,
                onTap: () {
                  Navigator.pushNamed(context, PackageGroupDetailPage.pageName, arguments: {
                    'packageGroup': PackageGroup.fromJson(current.toJson()),
                  });
                },
              );
            },
            itemCount: packageGroupProvider.packageGroups.length,
          );
        },
      ),
    );
  }
}
